package com.uit.gis.pojo;

import com.uit.gis.util.JsonData;
import com.uit.gis.util.Util.SpatialType;

import processing.data.JSONArray;
import processing.data.JSONObject;

public class CustomShape extends Shape {

	/**
	 * 
	 */
	JSONArray customShape = new JSONArray();
	private static final long serialVersionUID = 1L;

	@Override
	public void setup()
	{
		spatialType = SpatialType.CUSTOMSHAPE;
		background(255);
	}
	public void draw() {
		if(!continueDraw)
			return;
		stroke(0);
		if (mousePressed == true) {
			JSONObject line = new JSONObject();
			line.setInt("x1", mouseX);
			line.setInt("y1", mouseY);
			line.setInt("x2", pmouseX);
			line.setInt("y2", pmouseY);
			customShape.append(line);
			line(mouseX, mouseY, pmouseX, pmouseY);
		}
	}

	@Override
	public void mouseClicked(processing.event.MouseEvent e) {

		if (e.getButton() == processing.core.PConstants.RIGHT) {
			//saveJSONArray(customShape, "customShape.json");
			continueDraw = false;
			saveToTextFile();
		}
	}

	@Override
	public void saveToTextFile() {
		// TODO Auto-generated method stub
		saveJSONArray(customShape, getSavingPath());
		super.saveToTextFile();
	};
	@Override
	public JsonData loadDataFromFile() {
		// TODO Auto-generated method stub
		JSONArray jsonArray = loadJSONArray(getSavingPath());
		JsonData jsonData = new JsonData(jsonArray, null);
		return jsonData;
	};
	 
}
